package com.zzyl.service.impl;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.DeviceDataPageReqDto;
import com.zzyl.mapper.DeviceDataMapper;
import com.zzyl.service.DeviceDataService;
import com.zzyl.utils.ObjectUtil;
import com.zzyl.vo.DeviceDataVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @author yangeit
 * @date 2024年05月25日 16:08
 * @Description
 */
@Slf4j
@Service
public class DeviceDataServiceImpl implements DeviceDataService {

    @Autowired
    DeviceDataMapper deviceDataMapper;

    @Override
    public PageResponse<DeviceDataVo> page(DeviceDataPageReqDto deviceDataPageReqDto) {

        //分页查询
        PageHelper.startPage(deviceDataPageReqDto.getPageNum(), deviceDataPageReqDto.getPageSize());

        //查询条件
        Long startTime = deviceDataPageReqDto.getStartTime();
        Long endTime = deviceDataPageReqDto.getEndTime();

        deviceDataPageReqDto.setStartDate(ObjectUtil.isEmpty(startTime) ? null : LocalDateTimeUtil.of(startTime));
        deviceDataPageReqDto.setEndDate(ObjectUtil.isEmpty(endTime) ? null : LocalDateTimeUtil.of(endTime));


        Page<DeviceDataVo> page = deviceDataMapper.page(deviceDataPageReqDto);

        return PageResponse.of(page, DeviceDataVo.class);

    }
}
